package com.jsb.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jsb.mapper.AdminMapper;
import com.jsb.model.Admin;
import com.jsb.model.AdminExample;
import com.jsb.model.AdminExample.Criteria;

@Service
public class AdminService{
	
	@Resource
	private AdminMapper adminMapper;
	
	public void addAdmin(Admin admin) {
		adminMapper.insertSelective(admin);
	}
	
	public void delAdminById(String id) {
		adminMapper.deleteByPrimaryKey(id);
	}
	
	public void updateAdmin(Admin admin) {
		adminMapper.updateByPrimaryKeySelective(admin);
	}
	
	public void updateAdminByExample(Admin admin,AdminExample adminExample){
	    adminMapper.updateByExampleSelective(admin,adminExample);
	}
	
	public Admin getAdminById(String id) {
		return adminMapper.selectByPrimaryKey(id);
	}
	
	public List<Admin> getPageAdmin(AdminExample adminExample) {
		return adminMapper.selectPage(adminExample);
	}
	
	public int countAdmin(AdminExample adminExample) {
		return adminMapper.countByExample(adminExample);
	}
	
	public List<Admin> selectByExample(AdminExample example){
	    return adminMapper.selectByExample(example);
	}
	
	public Admin getUserByAccount(String account){
		AdminExample example = new AdminExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andAccountEqualTo(account);
		List<Admin> admins = adminMapper.selectByExample(example);
		if(null != admins && admins.size() ==1){
			return admins.get(0);
		}
		return null;
	}
}
